"use strict";
var license = require("../utils/license");
var render = function() {
  var _vm = this;
  var _h = _vm.$createElement;
  var _c = _vm._self._c || _h;
  return _vm.authenticated ? _c("div", { staticClass: "ele-tags-input" }, [_vm._l(_vm.data, function(item, index2) {
    return _c("el-tag", { key: item + "-" + index2, attrs: { "size": _vm.size, "type": _vm.type, "effect": _vm.effect, "closable": true, "disable-transitions": true }, on: { "close": function($event) {
      return _vm.onClose(index2);
    } } }, [_vm._v(" " + _vm._s(item) + " ")]);
  }), _c("el-tooltip", { attrs: { "value": _vm.edit && !!_vm.message, "content": _vm.message, "placement": "top", "manual": true, "transition": _vm.transition } }, [_c("el-input", { directives: [{ name: "show", rawName: "v-show", value: _vm.edit, expression: "edit" }], ref: "input", style: { width: _vm.width }, attrs: { "size": _vm.size, "disabled": _vm.loading, "suffix-icon": _vm.loading ? "el-icon-loading" : void 0 }, on: { "blur": _vm.onEdit }, nativeOn: { "keyup": function($event) {
    if (!$event.type.indexOf("key") && _vm._k($event.keyCode, "enter", 13, $event.key, "Enter")) {
      return null;
    }
    return _vm.onEdit.apply(null, arguments);
  } }, model: { value: _vm.text, callback: function($$v) {
    _vm.text = $$v;
  }, expression: "text" } })], 1), _c("el-button", { directives: [{ name: "show", rawName: "v-show", value: !_vm.edit, expression: "!edit" }], style: { width: _vm.width }, attrs: { "size": _vm.size }, on: { "click": _vm.showEdit } }, [_vm._v(" " + _vm._s(_vm.placeholder) + " ")])], 2) : _vm._e();
};
var staticRenderFns = [];
function normalizeComponent(scriptExports, render2, staticRenderFns2, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
  var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports;
  if (render2) {
    options.render = render2;
    options.staticRenderFns = staticRenderFns2;
    options._compiled = true;
  }
  if (functionalTemplate) {
    options.functional = true;
  }
  if (scopeId) {
    options._scopeId = "data-v-" + scopeId;
  }
  var hook;
  if (moduleIdentifier) {
    hook = function(context) {
      context = context || this.$vnode && this.$vnode.ssrContext || this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext;
      if (!context && typeof __VUE_SSR_CONTEXT__ !== "undefined") {
        context = __VUE_SSR_CONTEXT__;
      }
      if (injectStyles) {
        injectStyles.call(this, context);
      }
      if (context && context._registeredComponents) {
        context._registeredComponents.add(moduleIdentifier);
      }
    };
    options._ssrRegister = hook;
  } else if (injectStyles) {
    hook = shadowMode ? function() {
      injectStyles.call(this, (options.functional ? this.parent : this).$root.$options.shadowRoot);
    } : injectStyles;
  }
  if (hook) {
    if (options.functional) {
      options._injectStyles = hook;
      var originalRender = options.render;
      options.render = function renderWithStyleInjection(h, context) {
        hook.call(context);
        return originalRender(h, context);
      };
    } else {
      var existing = options.beforeCreate;
      options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
    }
  }
  return {
    exports: scriptExports,
    options
  };
}
const __vue2_script = {
  name: "EleTagsInput",
  model: {
    prop: "data",
    event: "change"
  },
  props: {
    data: {
      type: Array,
      required: true
    },
    type: String,
    size: String,
    effect: String,
    placeholder: {
      type: String,
      default: "+ New Tag"
    },
    width: {
      type: String,
      default: "90px"
    },
    unique: {
      type: Boolean,
      default: true
    },
    uniqueMessage: {
      type: String,
      default: "${value}\u5DF2\u7ECF\u5B58\u5728"
    },
    validator: [Function, Array],
    beforeRemove: Function,
    transition: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      authenticated: license.checkLicense(),
      edit: false,
      text: "",
      message: "",
      loading: false
    };
  },
  methods: {
    showEdit() {
      this.edit = true;
      this.message = "";
      this.$nextTick(() => {
        var _a, _b, _c;
        (_c = (_b = (_a = this.$refs.input) == null ? void 0 : _a.$refs) == null ? void 0 : _b.input) == null ? void 0 : _c.focus();
      });
    },
    addTag(value) {
      this.edit = false;
      this.text = "";
      this.message = "";
      this.loading = false;
      this.$emit("change", this.data.concat([value]));
    },
    onEdit() {
      var _a;
      if (!this.text) {
        this.edit = false;
        this.message = "";
        return;
      }
      if (this.unique && ((_a = this.data) == null ? void 0 : _a.includes(this.text))) {
        this.message = this.uniqueMessage.replace("${value}", this.text);
        return;
      }
      this.loading = true;
      if (typeof this.validator === "function") {
        Promise.resolve(this.validator(this.text)).then((result) => {
          if (result === false) {
            this.loading = false;
            this.message = "";
          } else {
            this.addTag(this.text);
          }
        }).catch((e) => {
          var _a2;
          this.loading = false;
          this.message = (_a2 = e == null ? void 0 : e.message) != null ? _a2 : "";
        });
      } else if (Array.isArray(this.validator)) {
        if (!new RegExp(this.validator[0]).test(this.text)) {
          this.loading = false;
          this.message = this.validator[1] || "\u6821\u9A8C\u4E0D\u901A\u8FC7";
        } else {
          this.addTag(this.text);
        }
      } else {
        this.addTag(this.text);
      }
    },
    onClose(index2) {
      if (!this.beforeRemove) {
        this.removeTag(index2);
        return;
      }
      Promise.resolve(this.beforeRemove(index2, this.data ? this.data[index2] : void 0)).then((result) => {
        if (result !== false) {
          this.removeTag(index2);
        }
      }).catch(() => {
      });
    },
    removeTag(index2) {
      var _a, _b, _c;
      const data = (_c = (_a = this.data) == null ? void 0 : _a.slice(0, index2)) == null ? void 0 : _c.concat((_b = this.data) == null ? void 0 : _b.slice(index2 + 1, this.data.length));
      this.$emit("change", data);
    }
  },
  deactivated() {
    this.message = "";
  }
};
const __cssModules = {};
var __component__ = /* @__PURE__ */ normalizeComponent(__vue2_script, render, staticRenderFns, false, __vue2_injectStyles, null, null, null);
function __vue2_injectStyles(context) {
  for (let o in __cssModules) {
    this[o] = __cssModules[o];
  }
}
var index = /* @__PURE__ */ function() {
  return __component__.exports;
}();
module.exports = index;
